package com.yufan.frame.shardingsphere;


import com.yufan.dao.sharding.TestMapping;
import com.yufan.dto.Order;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ShardingSphereTest {

    private TestMapping testMapping;

    public ShardingSphereTest(TestMapping testMapping) {
        this.testMapping = testMapping;
    }

    @GetMapping("/order/add")
    public String addOrder(Integer orderId,Integer userId, String orderName) {
        testMapping.addOrder(new Order(orderId,userId,orderName));
        return "OK";
    }

    @GetMapping("/order/get")
    public String getOrders() {
        List<Order> orders = testMapping.findOrders();
        return orders.toString();
    }
}
